<!-- 报价设置 -->
<template>
	<div class="price_setting">
		<div class="setting_support">
			<div class="label">是否支持报价：</div>
			<a-radio-group v-model="quotationSupported" @change="changeQuotedInfo">
				<a-radio :value="0">
					否
				</a-radio>
				<a-radio :value="1">
					是
				</a-radio>
			</a-radio-group>
		</div>
		<div class="content" v-show="quotationSupported == 1">
			<search-table :url="url" ref="searchtable" :columns="columns">
				<template slot="searchForm">
				</template>
				<template slot="oprationRow">
					<permission authority="quoted:property:add">
						<a-button type="primary" icon="plus" @click="openInfo()">新增属性</a-button>
					</permission>
					<permission authority="quoted:property:delete">
						<a-button @click="deleteRows($refs.searchtable.selectedRowKeys)" type="primary" icon="delete">删除</a-button>
					</permission>
				</template>
				<template slot="tableOperation" slot-scope="{ record }">
					<permission authority="quoted:property:modify">
						<span class="text-primary pointer" @click="openInfo(record)">编辑</span>
					</permission>
					<a-divider type="vertical" />
					<permission authority="quoted:property:delete">
						<span class="text-danger pointer" @click="deleteRows([record.id])">删除</span>
					</permission>
				</template>
			</search-table>
			<PriceSettingForm :record="currentRecord" @cancel="closeInfoModal" :visible="infoVisible" />
		</div>
	</div>
</template>

<script>
import PriceSettingForm from './components/PriceSettingForm'
export default {
	name: 'GalleryGallerySettingPriceSetting',
	components: {
    PriceSettingForm
  },
	directives: {},
	filters: {},
	mixins: [],
	model: {},
	props: {},
	data () {
		return {
			quotationSupported: '', // （0.否 1.是）
			url: '/quoted/property/page',
			infoVisible: false,
			currentRecord: {},
			columns: [
				{
					title: '属性名称',
					dataIndex: 'quotedName',
					key: 'quotedName'
          // width: '500'
				},
				{
					title: '操作',
					dataIndex: 'operation',
					scopedSlots: { customRender: 'operation' },
          width: 150
				}
			]
		}
	},
	computed: {},
	watch: {},
	beforeCreate () {},
	created () {
    this.queryQuotedInfo()
  },
	beforeMount () {},
	mounted () {},
	beforeUpdate () {},
	updated () {},
	activated () {},
	deactivated () {},
	beforeDestroy () {},
	destroyed () {},
	// 方法集合
	methods: {
    async changeQuotedInfo (e) {
      const val = e.target.value
      const res = await this.$post('/quoted/config/update', {
        quotationSupported: val
      })
      if (res.returnCode == 1000) {
        // this.quotationSupported = val
      }
      console.log('changeQuotedInfo', res)
    },
    async queryQuotedInfo () {
      const res = await this.$get('/quoted/config/query')
      if (res.returnCode == 1000) {
        this.quotationSupported = res.dataInfo.quotationSupported
      }
      console.log('queryQuotedInfo', res)
    },
		onChange (val) {},
		closeInfoModal (freshTable) {
			this.infoVisible = false
			if (freshTable) {
				this.$refs.searchtable.refreshTable()
			}
		},
		openInfo (record) {
      console.log('编辑的record', record)
			this.currentRecord = record
			this.infoVisible = true
		},
		deleteRows (ids) {
      console.log('ids', ids)
			if (!ids || ids.length === 0) return this.$message.warn('请先选择一项后再进行操作')
			this.$confirm({
				title: '删除提示',
				content: '删除操作不可恢复，请确认是否删除？',
				okText: '确认删除',
				cancelText: '取消',
				onOk: () => {
					this.$post('/quoted/property/delete', ids).then((res) => {
						if (res && res.returnCode == 1000) {
							this.$message.success('删除成功')
							this.$refs.searchtable.refreshTable()
						}
					})
				}
			})
		}
	}
}
</script>
<style rel="stylesheet/less" lang="less" scoped>
//@import url();
.price_setting {
	.setting_support {
		display: flex;
		align-items: center;
		height: 80px;
		background: #f5f5f5;
		border-radius: 4px;
		padding-left: 32px;
		.label {
			font-size: 14px;
			font-family: MicrosoftYaHei;
			color: #333333;
			margin-right: 10px;
		}
	}
}
</style>
